package com.tn.openrpc.channel;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * <code>RemoteChannelResponse</code> represents a response received from a <code>RemoteChannel</code>.
 */
public class RemoteChannelResponse implements Serializable
{
  private Object result;

  /**
   * Creates a new <code>RemoteChannelResponse</code> initialized with the <code>result</code>.
   */
  public RemoteChannelResponse(Object result)
  {
    this.result = result;
  }

  /**
   * Creates a new <code>RemoteChannelRequest</code>.  This constructor is required in order for AMF serialization to work and should not
   * otherwise be used.
   */
  public RemoteChannelResponse()
  {
    //Intentionally blank - see JavaDoc.
  }

  /**
   * Returns the result.
   */
  public Object getResult()
  {
    return result;
  }

  /**
   * Sets the result.  This setter is required in order for AMF serialization to work and should not otherwise be used.
   */
  public void setResult(Object result)
  {
    this.result = result;
  }

  /**
   * Compares this object to another for equality.  For another object to be considered equal to a
   * <code>RemoteChannelRequest</code> the other object must be a <code>RemoteChannelRequest</code> and must have been
   * initialized with the same values.
   *
   * @param other the other object.
   * @return <code>true</code> if the objects are considered equal, otherwise <code>false</code>.
   */
  @Override
  public boolean equals(Object other)
  {
    return this == other || other != null && getClass() == other.getClass() &&
      new EqualsBuilder()
        .append(getResult(), ((RemoteChannelResponse) other).getResult())
        .isEquals();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int hashCode()
  {
    return new HashCodeBuilder()
      .append(getResult())
      .toHashCode();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String toString()
  {
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
      .append("result", getResult())
      .toString();
  }
}
